<!-- 登录页面 -->
<template>
    <!--登录表单的容器 -->
  <div class="login_container">
      <!--登录区域 -->
        <div class="login_box">
            <!-- 头像 -->
            <div class="avatar_box">
                <img src="../assets/img/touxiang.jpg" alt="">
            </div>
            <!-- 表单 -->
            <div class="">
                <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="0px" class="login_form">
                <el-form-item label="" prop="username">
                    <el-input v-model="loginForm.username" prefix-icon="el-icon-user-solid"></el-input>
                </el-form-item>
                <el-form-item label="" prop="password">
                    <el-input v-model="loginForm.password" prefix-icon="el-icon-lock"></el-input>
                </el-form-item>
                <el-form-item label="" prop="verifyCode">
                    <div class="verifyCode_box">
                        <el-input v-model="loginForm.verifyCode" prefix-icon="el-icon-mobile" class="verify_code"></el-input>
                        <img src="../assets/img/msFXK1.jpg" alt="" class="verifyCode_img">
                    </div>
                </el-form-item>
                <el-form-item class="login_btn">
                    <el-button type="primary" @click="submitForm('loginForm')">立即创建</el-button>
                    <el-button @click="resetForm('loginForm')">重置</el-button>
                </el-form-item>
                </el-form>
            </div>
        </div>
  </div>
</template>

<script>
export default {
    name:'Login',
     data() {
      return {
        loginForm: {
          username: '',
          password: '',
          verifyCode: ''
        },
        loginRules: {
          username: [
            { required: true, message: '请输入用户名称', trigger: 'blur' },
            { min: 3, max: 16, message: '长度在 3 到 16 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入登录密码', trigger: 'blur' },
            { min: 3, max: 16, message: '长度在 3 到 16 个字符', trigger: 'blur' }
          ],
          verifyCode: [
            { required: true, message: '请输入验证码', trigger: 'blur' },
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$router.push('/main');  //通过路由登录成功后跳转到main页面
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
}
</script>

<style lang="less" scoped>
    .login_container{
        height: 100%;
        background-image: url('../assets/img/bgt.jpg');
        background-repeat: no-repeat;
        background-size: 100%;
    }
    .login_box{
        width:450px;
        height: 380px;
        background-color:#ffffff;
        border-radius: 3px;
        position: absolute;
        left: 40%;
        top: 50%;
        transform: translate(-50%,-50%);

        /* 使用less */
        .avatar_box{
            width: 130px;
            height: 130px;
            border: 1px solid #EEEEEE;
            border-radius: 50%;
            padding: 10px;
            box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1); /* 阴影 */
            margin: -65px auto;
            background-color: #ffffff;
        }

        img{
            width: 100%;
            height: 100%;
            border-radius: 50%;
            background-color: #eeeeee;
        }
    }
    .login_form{
        position: absolute;
        bottom: 0px;
        width: 100%;
        padding: 0px 20px;
        box-sizing: border-box;

        .login_btn{
            display: flex;
            justify-content: center;
        }

        .verifyCode_box{ 
            display: flex; 
            .verifyCode{ 
                width: 70%; 
                justify-content: left; 
            }
            .verifyCode_img{ 
                width: 30%; 
                height: 45px; 
                justify-content: 
                flex-end; 
            }
        }
    }
</style>